package com.starblink.android.basic.widget.swipe
import android.content.Context
import android.util.AttributeSet
import androidx.annotation.NonNull
import androidx.annotation.Nullable
import com.google.android.material.tabs.TabLayout
class MFTabLayout @JvmOverloads constructor(@NonNull context: Context, @Nullable attrs: AttributeSet? = null, defStyleAttr: Int = 0) :
    TabLayout(context, attrs, defStyleAttr) {

    var disableClickPosition: Int = -1 // default -1, 不禁用，如1，表示禁止点击position为1的tab
    var disableClickPositionListener: (tab: Tab?) -> Unit = {} // 当想监听某个被禁止点击position的tab点击事件时

    fun resetDisableClickPosition() {
        disableClickPosition = -1
    }

    override fun selectTab(tab: Tab?) {
        // 如果点击的tab索引与期望的索引一致，进行拦截，并调用listener(disableClickPositionListener)，然后返回
        if ((tab?.position ?: 0) == disableClickPosition) {
            disableClickPositionListener(tab)
            return
        }
        super.selectTab(tab)
    }
}